package com.neu.servlet.snn;


import com.alibaba.fastjson.JSONObject;
import com.neu.service.snn.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "FenYeServlet", urlPatterns = {"/FenYeServlet.do"})
public class FenYeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //默认显示第一页
        response.setCharacterEncoding("UTF-8");
        UserService userService = new UserService();
        Object pageNum=userService.getPageNum(3);
        List<Map<String,Object>> list=userService.findByPage("1",3);
        HttpSession session=request.getSession();
        session.setAttribute("pageIndex","1");
        session.setAttribute("pageNum",pageNum);
        String json=JSONObject.toJSONString(list);
        System.out.println(json);
        PrintWriter out=response.getWriter();
        out.write(json);
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
